﻿using System;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Generic;

using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;

namespace Cyberwolf.Modules.PWCAPAdmin
{
    public partial class Settings : ModuleSettingsBase
    {
        #region Override Methods
        public override void LoadSettings()
        {
            try
            {
                if (!IsPostBack)
                {
                    object oServerName = ModuleSettings["SERVER_NAME"];
                    if (oServerName != null)
                    {
                        txtServerName.Text = oServerName.ToString();
                    }

                    object oServiceURL = ModuleSettings["SERVICE_URL"];
                    if (oServiceURL != null)
                    {
                        txtServiceURL.Text = oServiceURL.ToString();
                    }

//                    object oOrganizationURL = ModuleSettings["ORGANIZATION_URL"];
//                    if (oOrganizationURL != null)
//                    {
//                        txtOrganizationURL.Text = oOrganizationURL.ToString();
//                    }
//#if DEBUG
//                    else
//                    {
//                        txtOrganizationURL.Text = "http://appadmin.cyberwolf.com";
//                    }
//#endif

//                    object oUsername = ModuleSettings["USERNAME"];
//                    if (oUsername != null)
//                    {
//                        txtUsername.Text = oUsername.ToString();
//                    }
//#if DEBUG
//                    else
//                    {
//                        txtUsername.Text = "kstevenson";
//                    }
//#endif

//                    object oPassword = ModuleSettings["PASSWORD"];
//                    if (oPassword != null)
//                    {
//                        txtPassword.Text = oPassword.ToString();
//                    }
//#if DEBUG
//                    else
//                    {
//                        Page.ClientScript.RegisterStartupScript(this.GetType(), "PASSWORD", "document.getElementById('" + txtPassword.ClientID + "').value = 'password';", true);
//                    }
//#endif
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        public override void UpdateSettings()
        {
            try
            {
                ModuleController oModuleController = new ModuleController();

                oModuleController.UpdateModuleSetting(ModuleId, "SERVER_NAME", txtServerName.Text);
                oModuleController.UpdateModuleSetting(ModuleId, "SERVICE_URL", txtServiceURL.Text);
                //oModuleController.UpdateModuleSetting(ModuleId, "ORGANIZATION_URL", txtOrganizationURL.Text);
                //oModuleController.UpdateModuleSetting(ModuleId, "USERNAME", txtUsername.Text);
                //oModuleController.UpdateModuleSetting(ModuleId, "PASSWORD", txtPassword.Text);
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        #endregion

        #region Private Methods
        #endregion
    }
}